<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('列表')" />
</head>
<body class="gray-bg">
    
     <div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="formId">
					<input type="hidden" id="channelId" name="channelId" th:value="${mpChannelMethod.id}">
					<div class="select-list">
						<ul>
							<li>
								支付类型：
								<select  id="payKindName" name="payKindName"></select>
							</li>

							<li>
								钱包类型：
								<select  id="walletKindName" name="walletKindName"></select>
							</li>
							<li>
								状态：<select name="status" th:with="type=${@dict.getType('sys_normal_disable')}">
								<option value="">所有</option>
								<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
							</select>
							</li>
							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
								<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
			
	        <div class="btn-group-sm" id="toolbar" role="group">
				<a class="btn btn-success" onclick="addPayMethod()">
					<i class="fa fa-plus"></i> 添加
				</a>
				<a class="btn btn-warning" onclick="$.table.exportExcel()">
						<i class="fa fa-download"></i> 导出
				 </a>
			</div>
			<div class="col-sm-12 select-table table-striped">
				<table id="bootstrap-table" data-mobile-responsive="true"></table>
			</div>
		</div>
	</div>
    <div th:include="include :: footer"></div>
    <script th:inline="javascript">
        var prefix = ctx + "channel/method";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
				exportUrl: prefix + "/export",
                queryParams: queryParams,
                modalName: "渠道支付方法",
		        showExport: true,
                columns: [{
		            checkbox: true
		        },
				{
					field : 'id', 
					title : 'id',
					visible: false
				},
                {
                    field : 'channelId',
                    title : '渠道标识',
                    visible: false,
                    sortable: true
                },
                {
                    field : 'channelName',
                    title : '渠道名称',
                    sortable: true
                },
                {
                    field : 'payKindId',
                    title : '支付类型标识',
                    visible: false,
                    sortable: true
                },
                {
                    field : 'payKindName',
                    title : '支付类型',
                    sortable: true
                },
                {
                    field : 'walletKindId',
                    title : '钱包类型标识',
                    visible: false,
                    sortable: true
                },
                {
                    field : 'walletKindName',
                    title : '钱包类型',
                    sortable: true
                },
				{
					field : 'payRate',
					title : '支付费率',
					sortable: true,
                    formatter: function (value, row, index) {
                        var data = value.toFixed(4);
                        return data;
                    }
				},
                {
                    field : 'payLimitLeft',
                    title : '支付限额(元)',
                    align: 'center',
                    sortable: true,
                    formatter: function (value, row, index) {
                        var payLimitLeft = new Decimal(value).div(new Decimal(100)).toFixed(2);
                        var payLimitRight = new Decimal(row.payLimitRight).div(new Decimal(100)).toFixed(2);
                        return payLimitLeft + "-" + payLimitRight;
                    }
                },
                {
                    field : 'status',
                    title : '状态',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return mpChannelMethod_statusTools(row);
                    }
                },
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	var actions = [];
		            	actions.push('<a class="btn btn-success btn-xs ' + '" href="#" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + '" href="#" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
						return actions.join('');
		            }
		        }]
            };
            $.table.init(options);


			/*支付类型标识下拉框*/
			$.post(ctx + "basedata/paykind/list", {'name':''},function (response) {
				var data = response.rows;
				var option = "<option value=''>" + "全部" + "</option>";
				for (var i = 0; i < data.length; i++) {
					option += "<option value='"+ data[i].name +"'>" + data[i].name + "</option>"
				}
				$("#formId").find("select[name='payKindName']").html("").append(option);
			});

			/*钱包类型标识下拉框*/
			$.post(ctx + "basedata/walletkind/list", {'name':''},function (response) {
				var data = response.rows;
				var option = "<option value=''>" + "全部" + "</option>";
				for (var i = 0; i < data.length; i++) {
					option += "<option value='"+ data[i].name +"'>" + data[i].name + "</option>"
				}
				$("#formId").find("select[name='walletKindName']").html("").append(option);
			});
        });


		// 渠道id
        function queryParams(params) {
            var search = $.table.queryParams(params);
            search.channelId = $("#channelId").val();
            return search;
        }

        // 添加支付方法
		function addPayMethod() {
            var url = prefix + '/add/' + $("#channelId").val();
            $.modal.open("添加【渠道-支付方法】", url);
        }

        /**
         *渠道支付方法状态显示
         */
        function mpChannelMethod_statusTools(row) {
            if (row.status == 1) {
                return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="mpChannelMethod_enable(\'' + row.id + '\')"></i> ';
            } else {
                return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="mpChannelMethod_disable(\'' + row.id + '\')"></i> ';
            }
        }

        /**
         * 渠道支付方法状态-停用
         */
        function mpChannelMethod_disable(mpChannelId) {
            $.modal.confirm("确认要停用所选渠道支付方法吗？", function () {
                $.operate.post(prefix + "/changeStatus", {"id": mpChannelId, "status": 1})
            });
        }


        /**
         * 渠道支付方法状态-启动
         */
        function mpChannelMethod_enable(mpChannelId) {
            $.modal.confirm("确认要启用所选渠道支付方法吗？", function () {
                $.operate.post(prefix + "/changeStatus", {"id": mpChannelId, "status": 0})
            });
        }

	</script>
</body>
</html>